package com.junjun.ssm.controller;

import com.junjun.ssm.entity.NewsEntity;
import com.junjun.ssm.servilce.INewsService;
import com.junjun.ssm.util.SnowIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("news")
public class NewsController {

    @Autowired
    INewsService newsService;

    @PostMapping("add")
    public String add(String title, String author, String createDate, String info) {
        String userid = SnowIdUtils.uniqueLongHex();

        newsService.add(userid, title, author, info, createDate);


        return null;
    }

    @PostMapping("selectAll")
    public List<NewsEntity> selectAll(String queryInfo) {




        return newsService.selectAll(queryInfo);
    }


    @PostMapping("queryEsById")
    public String queryEsById(String id) {

        String news = String.valueOf(newsService.queryEsById(id).getInfo());

        return news;
    }



    @PostMapping("deleteById")
    public void deleteById(String id) {

        newsService.deleteById(id);


    }

}
